package com.iwdm.renovation.ui.decoration;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.ChatActivity;
import com.iwdm.renovation.R;
import com.iwdm.renovation.databinding.FragmentDecorationBinding;
import com.iwdm.renovation.ui.decoration.details.DecorationActivity;

public class MyDecorationRecyclerViewAdapter extends RecyclerView.Adapter<MyDecorationRecyclerViewAdapter.ViewHolder> {

    private FragmentDecorationBinding binding;

    public MyDecorationRecyclerViewAdapter() {
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        binding = FragmentDecorationBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.textView.setText(position%2==0?"贝于装饰 专注全案设计":"于贝装饰 小家精装");
        holder.imageView.setImageResource(position%3==0? R.drawable.img2: R.drawable.img1);
        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), ChatActivity.class));
            }
        });
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), DecorationActivity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return 20;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final TextView textView;
        public final ImageView imageView;
        public Button btn;

        public ViewHolder(FragmentDecorationBinding binding) {
            super(binding.getRoot());
            mView = binding.getRoot();
            textView = binding.text;
            imageView = binding.img;
            btn = binding.btn;
        }
    }
}
